package com.dsr.config;

import com.dsr.consts.Result;
import com.dsr.exception.FlowerException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = FlowerException.class)
    public ResponseEntity<Result> responseEntity(FlowerException flowerException){
        return ResponseEntity.status(HttpStatus.OK)
                .body(Result.error(flowerException.getHttpStatus().value(),flowerException.getMessage()));
    }

//    @ExceptionHandler(value =Exception.class)
//    public ResponseEntity<Result> exceptionHandler(Exception e){
//        return ResponseEntity.status(HttpStatus.OK).body(Result.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),e.getMessage()));
//    }
}
